package com.kim.androidbase.tools;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateAndValueOfUtils {

	public static final SimpleDateFormat HHmm = new SimpleDateFormat("HH:mm");

	public static final SimpleDateFormat yyyy_MM_dd = new SimpleDateFormat(
			"yyyy-MM-dd");
	public static final SimpleDateFormat yyyy_MM_dd_HH_mm = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm");
	public static final SimpleDateFormat yyyy_MM_dd_HH_mm_ss = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss");
	public static final SimpleDateFormat yyyyMMddHHmmss = new SimpleDateFormat(
			"yyyyMMddHHmmss");
	public static final SimpleDateFormat yyyyMMdd = new SimpleDateFormat(
			"yyyy.MM.dd");
	public static final SimpleDateFormat MM_dd = new SimpleDateFormat("MM-dd");
	public static final SimpleDateFormat yyyy_MM_dd_HH_mm_ss_SSSZ = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss.SSSZ");
	public static final SimpleDateFormat yyyy_MM_dd_HH_mm_ss_CN = new SimpleDateFormat(
			"yyyy年 MM月 dd日 HH:mm:ss");
	public static final SimpleDateFormat yyyy_MM_dd_HH_mm_ss_EEE = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss EEE");

	public static String DateToString(SimpleDateFormat format, Date date,
			String defValue) {
		String reValue;
		try {
			if (date == null) {
				reValue = defValue;
			} else {
				reValue = format.format(date);
			}
		} catch (Exception e) {
			reValue = defValue;
		}
		return reValue;
	}

	public static Date StringToDate(SimpleDateFormat format, String strDate,
			Date defValue) {
		Date date;
		try {
			if (strDate == null || "".equals(strDate)) {
				date = defValue;
			} else {
				date = format.parse(strDate);
			}
		} catch (ParseException e) {
			e.printStackTrace();
			date = defValue;
		}
		return date;
	}

	public static int strToInt(String str, int defValue) {
		int reValue;
		if (str == null || "".equals(str)) {
			reValue = defValue;
		} else {
			try {
				reValue = Integer.parseInt(str);
			} catch (Exception e) {
				reValue = defValue;
			}
		}
		return reValue;
	}

	public static String intToStr(int num, String defValue) {
		String reValue;
		try {
			reValue = String.valueOf(num);
		} catch (Exception e) {
			reValue = defValue;
		}
		return reValue;
	}

	public static float strToFloat(String str, float defValue) {
		float reValue;
		if (str == null || "".equals(str)) {
			reValue = defValue;
		} else {
			try {
				reValue = Float.parseFloat(str);
			} catch (Exception e) {
				reValue = defValue;
			}
		}
		return reValue;
	}

	public static String doubleToString(double num, String defValue) {
		String reValue;
		try {
			reValue = String.valueOf(num);
		} catch (Exception e) {
			reValue = defValue;
		}
		return reValue;
	}

}
